package com.nbst.controller.base;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.nbst.comnutil.NormalResult;
import com.nbst.comnutil.Tools;
import com.nbst.model.base.RolePermission;
import com.nbst.service.base.IRolePermissionService;

/**
 * @ClassName: RolePermissionController
 * @Description:角色与权限的关系Controller
 * @author 兵
 * @date 2017-8-17
 * 
 */
@RestController
@RequestMapping("/RolePermission")
public class RolePermissionController {
	@Autowired
	IRolePermissionService rolepermissionservice;

	/**
	 * 
	 * @Title: getJsyqxList
	 * @Description: 获取角色与权限关系信息
	 * @param @param record RolePermission 实体类
	 * @param @return
	 * @return Object
	 * @throws
	 */
	@PostMapping(value = "/getJsyqxList.action")
	public Object getJsyqxList(RolePermission record) {
		Map<String,Object> map = Tools.transBean2Map(record);
		List<RolePermission> list = rolepermissionservice.findByCondition(map);
		return list;
	}

	/**
	 * 
	 * @Title: roleBulkaddPermission
	 * @Description: 为角色批量添加权限
	 * @param @param rId 角色ID
	 * @param @param pIds 权限ID数组
	 * @param @return
	 * @return NormalResult
	 * @throws
	 */
	@PostMapping(value = "/roleBulkaddPermission.action")
	public NormalResult roleBulkaddPermission(Integer rId, String[] pIds) {
		rolepermissionservice.deleteByrId(rId);
		return rolepermissionservice.roleBulkaddPermission(rId, pIds);
	}
	

	/**
	 * 
	 * @Title: insert
	 * @Description: 新增角色与权限关系信息
	 * @param @param record RolePermission实体类
	 * @param @param session
	 * @param @return
	 * @return NormalResult
	 * @throws
	 */
	@PostMapping(value = "/addNew.action")
	public NormalResult insert(RolePermission record, HttpSession session) {
		/*
		 * User user = (User) session.getAttribute("user");
		 * record.setCjr(user.getuAccount()); record.setCjrmc(user.getuName());
		 */
		Map<String,Object> map = Tools.transBean2Map(record);
		return rolepermissionservice.insertSelective(map);

	}

	/**
	 * 
	 * @Title: update
	 * @Description:修改角色与权限关系信息（包括删除）
	 * @param @param record RolePermission实体类
	 * @param @param session
	 * @param @return
	 * @return NormalResult
	 * @throws
	 */
	@PostMapping(value = "/updateJsyqxgx.action")
	public NormalResult update(RolePermission record, HttpSession session) {

		return rolepermissionservice.updateByPrimaryKeySelective(record);

	}

	/**
	 * 
	 * @Title: delete
	 * @Description: 物理删除角色与权限关系信息
	 * @param @param prId 主键ID
	 * @param @return
	 * @return NormalResult
	 * @throws
	 */
	@PostMapping(value = "/deleteJsyqxgx.action")
	public NormalResult delete(String prId) {
		return rolepermissionservice.deleteByPrimaryKey(prId);

	}

}